package pt.iscte.pcd.carrace;
import java.util.Random;

public class Car extends Thread {

	private Random r;
	private Track track;
	private int i;
	private int end;

	public Car(Track track, int i, int end) {
		r = new Random();
		this.track = track;
		this.i = i;
		this.end = end;
	}

	@Override
	public void run() {
		try {
			int progress = 0;
			//System.out.println("Car " + i + " started, running to " + end);
			while (progress < end) {
				//System.out.println("Car " + i + " progress " + progress);
				sleep(r.nextInt(100));
				progress++;
				track.setPosition(i, progress);
				track.repaint();
			}
		} catch (InterruptedException e) {

		}
	}

}
